Exercise 3: Integer Reversal

Directions

Given an integer, return an integer that is the reverse ordering of numbers.

Examples

reverseInt(15) === 51
  reverseInt(981) === 189
  reverseInt(500) === 5
  reverseInt(-15) === -51
  reverseInt(-90) === -9

Guidelines

The input and output should be a number, not a string Math.sign(), Number.prototype.toString(), Global.parseInt()

Solution

In [8]:
function reverseInt(n) {
  let result = parseInt(n.toString().split("").reverse().join(""));
  return result * Math.sign(n);
}
In [9]:
reverseInt(15)
Out[9]:
51
In [10]:
reverseInt(981)
Out[10]:
189
In [11]:
reverseInt(500)
Out[11]:
5
In [12]:
reverseInt(-15)
Out[12]:
-51
In [13]:
reverseInt(-90)
Out[13]:
-9